<!DOCTYPE html>
<html lang="zh" id="replace-style" xmlns:th="http://www.springframework.org/schema/jdbc">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="icon" type="image/x-icon"  >
    <title>websocket test</title>
</head>
<body>
<div>

</div>
<script th:src="@{/js/jquery-1.7.2.min.js}"></script>
<script type="text/javascript">
    $(document).ready(function () {
        //创建socket
        var websocket;
        function createWebsocket() {
            //var token = $('#Token').val();
            if ('WebSocket' in window) {
                websocket = new WebSocket("ws://127.0.0.1:9090/webSocketServer?id=12345&time=15061324");
            } else if ('MozWebSocket' in window) {
                websocket = new MozWebSocket("ws://127.0.0.1:9090/webSocketServer?id=12345&time=15061324");
            } else {
                websocket = new SockJS("ws://127.0.0.1:9090/webSocketServer?id=12345&time=15061324");
            }

            websocket.onopen = function(event) {
                console.log("WebSocket:已连接");
            };

            websocket.onmessage = function(event) {
                console.log("receiver message:"+event.data);
            };

            websocket.onerror = function(event) {
                console.log("WebSocket:发生错误 ");
            };

            websocket.onclose = function(event) {
                console.log("WebSocket:已关闭");
            }
        }

        //初始化WebSocket
        createWebsocket();
    });
</script>

</body>
</html>